<template>
  <view>
    <view class="my-search-container" :style="{'background-color':bgColor}">
      <!-- 使用view组件模拟input输入框的样式 -->
      <view class="my-search-box" :style="{'border-radius':radius+'px'}" @click="searchBoxHandler">
        <uni-icons type="search" size="17"></uni-icons>
        <text class="placeholder">搜索</text>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    props: {
      //搜索组件的背景颜色
      bgColor: {
        type: String,
        default: '#C00000'
      },
      //圆角尺寸
      radius: {
        type: Number,
        default: 18
      }
    },
    data() {
      return {

      };
    },
    methods:{
      //点击搜索框触发事件
      searchBoxHandler(){
        //向父组件传递seaarch事件
        this.$emit('search')
      }
    }
  }
</script>

<style lang="scss">
  .my-search-container {
    height: 50px;
    padding: 0 10px;
    display: flex;
    align-items: center;
  }

  .my-search-box {
    height: 36px;
    background-color: #ffffff;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .placeholder {
    font-size: 15px;
    margin-left: 5px;
  }
</style>
